﻿<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="CustomerContactSystem.Core" namespace="CustomerContactSystem.Core.Model">
    <class name="Enquiry" table="Enquiries">
        <id name="Id">
            <generator class="native" />
        </id>
        <property name="FixYourStreetId" not-null="true" />
        <property name="DateOfEnquiry" not-null="true" />
        <many-to-one name="Classification" class="EnquiryClassification" column="EnquiryClassificationId"  not-null="true" lazy="false" fetch="join" foreign-key="FK_Enquiries_EnquiryClassifications"></many-to-one>
        <many-to-one name="Category" class="EnquiryCategory" column="CategoryId"  not-null="true" lazy="false" fetch="join" foreign-key="FK_Enquiries_EnquiryCategories"></many-to-one>
        <many-to-one name="Source" class="EnquirySource" column="EnquirySourceId"  not-null="true" lazy="false" fetch="join" foreign-key="FK_Enquiries_EnquirySources"></many-to-one>
        <many-to-one name="SubmittedBy" class="User" column="SubmittedById"  not-null="true" fetch="join" foreign-key="FK_Enquiries_Users"></many-to-one>
        <many-to-one name="SubmittedByDepartment" class="Department" column="SubmittedByDepartmentId" not-null="true" fetch="join" foreign-key="FK_Enquiries_Departments"></many-to-one>
        <many-to-one name="SubmittedByGroup" class="UserGroup" column="SubmittedByGroupId"  not-null="true" fetch="join" foreign-key="FK_Enquiries_UserGroups"></many-to-one>
        <many-to-one name="Customer" class="Customer" column="CustomerId"  not-null="false" lazy="false" fetch="join" foreign-key="FK_Enquiries_Customers"></many-to-one>
        <many-to-one name="Rep" class="Rep" column="RepId"  not-null="false" lazy="false" fetch="join" foreign-key="FK_Enquiries_Reps"></many-to-one>
        <property name="EnquiryDetail" not-null="true" type="StringClob" />
        <property name="Deadline" not-null="true" />
        <property name="IsMediaEnquiry" not-null="true" />
        <property name="IsConfidential" not-null="true" />
        <property name="CurrentStatus" not-null="true" length="250" />
        <property name="FirstResponseTime" not-null="true" />
        <many-to-one name="FirstReferral" class="EnquiryFirstReferral" column="FirstReferralId" not-null="false" fetch="join" foreign-key="FK_Enquiries_FirstReferrals"></many-to-one>
        <many-to-one name="CurrentReferral" class="EnquiryCurrentReferral" column="CurrentReferralId" not-null="false" fetch="join" foreign-key="FK_Enquiries_CurrentReferrals"></many-to-one>
        <many-to-one name="Closure" class="EnquiryClosure" column="ClosureId" not-null="false" fetch="join" foreign-key="FK_Enquiries_EnquiryClosures"></many-to-one>
        <many-to-one name="CommitmentClosure" class="EnquiryCommitmentClosure" column="CommitmentClosureId" not-null="false" fetch="join" foreign-key="FK_Enquiries_CommitmentClosures"></many-to-one>
        <many-to-one name="Deletion" class="EnquiryDeletion" column="DeletionId" not-null="false" lazy="false" fetch="join" foreign-key="FK_Enquiries_EnquiryDeletions"></many-to-one>
        <set name="Tags" table="EnquiriesTags" access="field.camelcase-underscore" cascade="none" batch-size="50">
            <key column="EnquiryId"></key>
            <many-to-many column="TagId" class="Tag"/>
        </set>
        <set name="Avoidables" table="EnquiryAvoidables" access="field.camelcase-underscore" cascade="all-delete-orphan" batch-size="50" inverse="true">
            <key column="Enquiry" not-null="true"></key>
            <one-to-many class="EnquiryAvoidable"/>
        </set>
        <set name="Comments" table="EnquiryComments" access="field.camelcase-underscore" cascade="all-delete-orphan" inverse="true" batch-size="50" order-by="CommentDate asc">
            <key column="Enquiry" not-null="true"></key>
            <one-to-many class="EnquiryComment"/>
        </set>
        <set name="Documents" table="EnquiryDocuments" access="field.camelcase-underscore" cascade="all-delete-orphan" inverse="true" batch-size="50" order-by="DateAdded asc">
            <key column="Enquiry" not-null="true"></key>
            <one-to-many class="EnquiryDocument"/>
        </set>
        <set name="Referrals" table="EnquiryReferrals" access="field.camelcase-underscore" cascade="all-delete-orphan" inverse="true" batch-size="50" order-by="DateReferred asc">
            <key column="Enquiry" not-null="true"></key>
            <one-to-many class="EnquiryReferral"/>
        </set>
        <set name="History" table="EnquiryHistory" access="field.camelcase-underscore" cascade="all-delete-orphan" inverse="true" batch-size="50" order-by="EventDate asc">
            <key column="Enquiry" not-null="true"></key>
            <one-to-many class="EnquiryHistory"/>
        </set>
        <set name="FixYourStreetStatusUpdates" table="EnquiryFixYourStreetStatusUpdates" access="field.camelcase-underscore" cascade="all-delete-orphan" inverse="true" batch-size="50">
            <key column="Enquiry" not-null="true"></key>
            <one-to-many class="EnquiryFixYourStreetStatusUpdate"/>
        </set>
        <set name="Emails" table="EnquiryEmails" access="field.camelcase-underscore" cascade="all-delete-orphan" inverse="true" batch-size="50">
            <key column="Enquiry" not-null="true"></key>
            <one-to-many class="EnquiryEmail"/>
        </set>
    </class>
</hibernate-mapping>